View Javadoc

1   /*
2   * Copyright 2005 Arnaud Prost
3   * 
4   * Arnaud.prost@gmail.com
5   * 
6   * This software is a computer program whose purpose is to ease the 
7   * management of software project.
8   * 
9   * This software is governed by the CeCILL  license under French law and
10  * abiding by the rules of distribution of free software.  You can  use, 
11  * modify and/ or redistribute the software under the terms of the CeCILL
12  * license as circulated by CEA, CNRS and INRIA at the following URL
13  * "http://www.cecill.info". 
14  * 
15  * As a counterpart to the access to the source code and  rights to copy,
16  * modify and redistribute granted by the license, users are provided only
17  * with a limited warranty  and the software's author,  the holder of the
18  * economic rights,  and the successive licensors  have only  limited
19  * liability. 
20  * 
21  * In this respect, the user's attention is drawn to the risks associated
22  * with loading,  using,  modifying and/or developing or reproducing the
23  * software by the user in light of its specific status of free software,
24  * that may mean  that it is complicated to manipulate,  and  that  also
25  * therefore means  that it is reserved for developers  and  experienced
26  * professionals having in-depth computer knowledge. Users are therefore
27  * encouraged to load and test the software's suitability as regards their
28  * requirements in conditions enabling the security of their systems and/or 
29  * data to be ensured and,  more generally, to use and operate it in the 
30  * same conditions as regards security. 
31  * 
32  * The fact that you are presently reading this means that you have had
33  * knowledge of the CeCILL license and that you accept its terms.
34  */
35  
36  package net.sf.pmr.agilePlanning.domain.iteration;
37  
38  import java.util.Calendar;
39  import java.util.Date;
40  
41  import net.sf.pmr.agilePlanning.domain.release.Release;
42  import net.sf.pmr.core.domain.basicProject.BasicProject;
43  import net.sf.pmr.keopsframework.domain.object.AbstractDomainObject;
44  
45  import org.apache.commons.lang.builder.EqualsBuilder;
46  import org.apache.commons.lang.builder.HashCodeBuilder;
47  
48  /***
49   * @author Arnaud Prost (arnaud.prost@gmail.com)
50   */
51  public class IterationImpl extends AbstractDomainObject implements Iteration {
52  
53      /***
54       * basic Project
55       */
56      private BasicProject basicProject;
57  
58      /***
59       * start
60       */
61      private Date start;
62  
63      /***
64       * end
65       */
66      private Date end;
67  
68      /***
69       * release
70       */
71      private Release release;
72  
73      /***
74       * @see net.sf.pmr.agilePlanning.domain.iteration.Iteration#getBasicProject()
75       */
76      public BasicProject getBasicProject() {
77          return basicProject;
78      }
79  
80      /***
81       * @see net.sf.pmr.agilePlanning.domain.iteration.Iteration#setBasicProject(net.sf.pmr.core.domain.basicProject.BasicProject)
82       */
83      public void setBasicProject(final BasicProject basicProject) {
84          this.basicProject = basicProject;
85      }
86  
87      /***
88       * @see net.sf.pmr.agilePlanning.domain.iteration#getStart()
89       */
90      public Date getStart() {
91          return start;
92      }
93  
94      /***
95       * La date est tronquée au jour
96       *
97       * @see net.sf.pmr.agilePlanning.domain.iteration#setStart(java.util.Date)
98       */
99      public void setStart(final Date start) {
100 
101         this.start = roundDateToDay(start);
102 
103     }
104 
105     /***
106      * @see net.sf.pmr.agilePlanning.domain.iteration#getEnd()
107      */
108     public Date getEnd() {
109         return end;
110     }
111 
112     /***
113      * La date est tronquée au jour
114      *
115      * @see net.sf.pmr.agilePlanning.domain.iteration#setEnd(java.util.Date)
116      */
117     public void setEnd(final Date end) {
118 
119         this.end = roundDateToDay(end);
120 
121     }
122 
123     /***
124      * @see net.sf.pmr.agilePlanning.domain.iteration#getRelease()
125      */
126     public Release getRelease() {
127         return this.release;
128     }
129 
130     /***
131      * @see net.sf.pmr.agilePlanning.domain.iteration#setRelease(net.sf.pmr.agilePlanning.domain.Release)
132      */
133     public void setRelease(final Release release) {
134         this.release = release;
135     }
136 
137 
138     /***
139      * Arrondi la date donnée au jour Le nombre de milliseconde est positionné à
140      * 1 (pour ne pas changer de date si on est à minuit)
141      *
142      * @param date
143      *            à arrondir
144      * @return date arrondi
145      */
146     private Date roundDateToDay(final Date date) {
147 
148         if (date != null) {
149 
150             Calendar calendar = Calendar.getInstance();
151 
152             calendar.setTime(date);
153 
154             calendar.set(Calendar.HOUR_OF_DAY, 0);
155             calendar.set(Calendar.MINUTE, 0);
156             calendar.set(Calendar.SECOND, 0);
157             calendar.set(Calendar.MILLISECOND, 1);
158 
159             return calendar.getTime();
160 
161         } else {
162 
163             return date;
164 
165         }
166 
167     }
168     /***
169      * @see java.lang.Object#equals(Object)
170      */
171     public boolean equals(final Object object) {
172         if (!(object instanceof IterationImpl)) {
173             return false;
174         }
175         IterationImpl rhs = (IterationImpl) object;
176         return new EqualsBuilder().append(this.basicProject, rhs.basicProject)
177                                   .append(this.start, rhs.start)
178                                   .append(this.end, rhs.end)
179                                   .isEquals();
180     }
181     /***
182      * @see java.lang.Object#hashCode()
183      */
184     public int hashCode() {
185         return new HashCodeBuilder(522268527, -355299201).append(this.basicProject)
186                                                          .append(this.start)
187                                                          .append(this.end)
188                                                          .toHashCode();
189     }
190 }